/**
 * -----------------------------------
 *  Copyright (c) 2021-2025
 *  All rights reserved, Designed By www.linfengtech.cn
 *  林风社交论坛商业版本请务必保留此注释头信息
 *  商业版授权联系技术客服	 QQ:  3582996245
 *  严禁分享、盗用、转卖源码或非法牟利！
 *  版权所有 ，侵权必究！
 * -----------------------------------
 */
package io.linfeng.modules.admin.controller;

import java.util.Arrays;
import java.util.Map;

import io.linfeng.common.annotation.NoRepeatSubmit;
import io.linfeng.common.annotation.SysLog;
import io.linfeng.modules.admin.service.PostService;
import io.linfeng.modules.app.param.AdminUserInfoForm;
import io.linfeng.modules.app.param.AdminUserPunishForm;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.linfeng.modules.admin.entity.AppUserEntity;
import io.linfeng.modules.admin.service.AppUserService;
import io.linfeng.common.utils.PageUtils;
import io.linfeng.common.utils.R;



/**
 * 
 * 会员用户管理模块
 * @author linfeng
 * @email 2445465217@qq.com
 * @date 2022-01-20 12:10:43
 */
@RestController
@RequestMapping("admin/user")
@Api(tags = "管理端——用户管理")
public class AppUserController {

    @Autowired
    private AppUserService appUserService;

    @Autowired
    private PostService postService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @RequiresPermissions("admin:user:list")
    @ApiOperation("用户列表")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = appUserService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{uid}")
    @RequiresPermissions("admin:user:info")
    @ApiOperation("用户详情")
    public R info(@PathVariable("uid") Integer uid){
		AppUserEntity user = appUserService.getById(uid);

        return R.ok().put("user", user);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @RequiresPermissions("admin:user:save")
    @ApiOperation("用户保存")
    public R save(@RequestBody AppUserEntity user){
		appUserService.save(user);

        return R.ok();
    }

    /**
     * 修改
     */
    @SysLog("修改会员信息")
    @NoRepeatSubmit
    @PostMapping("/update")
    @RequiresPermissions("admin:user:update")
    @ApiOperation("修改会员信息")
    public R update(@RequestBody AdminUserInfoForm user){
		appUserService.updateUser(user);
        return R.ok();
    }

    /**
     * 处罚
     */
    @SysLog("处罚用户账号")
    @NoRepeatSubmit
    @PostMapping("/punish")
    @RequiresPermissions("admin:user:update")
    @ApiOperation("处罚用户账号")
    public R punish(@RequestBody AdminUserPunishForm param){
        appUserService.punishUser(param);
        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @RequiresPermissions("admin:user:delete")
    @ApiOperation("用户删除")
    public R delete(@RequestBody Integer[] uids){
		appUserService.removeByIds(Arrays.asList(uids));

        return R.ok();
    }


    @SysLog("禁用会员")
    @PostMapping("/ban/{id}")
    @RequiresPermissions("admin:user:update")
    @ApiOperation("禁用会员")
    public R ban(@PathVariable("id") Integer id){
		appUserService.ban(id);

        return R.ok();
    }


    @SysLog("解除会员禁用")
    @PostMapping("/openBan/{id}")
    @RequiresPermissions("admin:user:update")
    @ApiOperation("解除会员禁用")
    public R openBan(@PathVariable("id") Integer id){
		appUserService.openBan(id);

        return R.ok();
    }


    @SysLog("虚拟人机账户创建")
    @PostMapping("/createVirtualUser")
    @RequiresPermissions("admin:user:update")
    @ApiOperation("虚拟人机账户创建")
    public R ban(){

        postService.virtualUser();
        return R.ok();
    }



}
